package com.sptus.web.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sptus.common.core.domain.AjaxResult;
import com.sptus.framework.query.QueryGenerator;
import com.sptus.system.domain.SptDevLog;
import com.sptus.system.service.ISptDevLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

@Api(tags="spt_dev_log")
@RestController
@RequestMapping("/SptDevLog/sptDevLog")
@Slf4j
public class SptDevLogController {
   @Autowired
   private ISptDevLogService sptDevLogService;

   /**
    * 分页列表查询
    *
    * @param sptDevLog
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   //@AutoLog(value = "spt_dev_log-分页列表查询")
   @ApiOperation(value="spt_dev_log-分页列表查询", notes="spt_dev_log-分页列表查询")
   @GetMapping(value = "/list")
   public AjaxResult queryPageList(SptDevLog sptDevLog,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   HttpServletRequest req) {
       QueryWrapper<SptDevLog> queryWrapper = QueryGenerator.initQueryWrapper(sptDevLog, req.getParameterMap());
       queryWrapper.orderByDesc("create_time");
       Page<SptDevLog> page = new Page<SptDevLog>(pageNo, pageSize);
       IPage<SptDevLog> pageList = sptDevLogService.getSptLogs(page, queryWrapper);
       return AjaxResult.success(pageList);
   }

   /**
    *   添加
    *
    * @param sptDevLog
    * @return
    */
//   @AutoLog(value = "spt_dev_log-添加")
   @ApiOperation(value="spt_dev_log-添加", notes="spt_dev_log-添加")
   @PostMapping(value = "/add")
   public AjaxResult add(@RequestBody SptDevLog sptDevLog) {
       sptDevLogService.save(sptDevLog);
       return AjaxResult.success("添加成功！");
   }

   /**
    *  编辑
    *
    * @param sptDevLog
    * @return
    */
//   @AutoLog(value = "spt_dev_log-编辑")
   @ApiOperation(value="spt_dev_log-编辑", notes="spt_dev_log-编辑")
   @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
   public AjaxResult edit(@RequestBody SptDevLog sptDevLog) {
       sptDevLogService.updateById(sptDevLog);
       return AjaxResult.success("编辑成功!");
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
//   @AutoLog(value = "spt_dev_log-通过id删除")
   @ApiOperation(value="spt_dev_log-通过id删除", notes="spt_dev_log-通过id删除")
   @DeleteMapping(value = "/delete")
   public AjaxResult delete(@RequestParam(name="id",required=true) String id) {
       sptDevLogService.removeById(id);
       return AjaxResult.success("删除成功!");
   }

   /**
    *  批量删除
    *
    * @param ids
    * @return
    */
//   @AutoLog(value = "spt_dev_log-批量删除")
   @ApiOperation(value="spt_dev_log-批量删除", notes="spt_dev_log-批量删除")
   @DeleteMapping(value = "/deleteBatch")
   public AjaxResult deleteBatch(@RequestParam(name="ids",required=true) String ids) {
       this.sptDevLogService.removeByIds(Arrays.asList(ids.split(",")));
       return AjaxResult.success("批量删除成功!");
   }

   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   //@AutoLog(value = "spt_dev_log-通过id查询")
   @ApiOperation(value="spt_dev_log-通过id查询", notes="spt_dev_log-通过id查询")
   @GetMapping(value = "/queryById")
   public AjaxResult queryById(@RequestParam(name="id",required=true) String id) {
       SptDevLog sptDevLog = sptDevLogService.getById(id);
       if(sptDevLog==null) {
           return AjaxResult.error("未找到对应数据");
       }
       return AjaxResult.success(sptDevLog);
   }

   /**
   * 导出excel
   *
   * @param request
   * @param sptDevLog
   */
   /*@RequestMapping(value = "/exportXls")
   public ModelAndView exportXls(HttpServletRequest request, SptDevLog sptDevLog) {
       return super.exportXls(request, sptDevLog, SptDevLog.class, "spt_dev_log");
   }*/

   /**
     * 通过excel导入数据
   *
   * @param request
   * @param response
   * @return
   */
   /*@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
   public AjaxResult importExcel(HttpServletRequest request, HttpServletResponse response) {
       return super.importExcel(request, response, SptDevLog.class);
   }*/

}
